const { exec } = require('child_process');

const { PROJECT_PATH } = require('../config')


const sd = require('silly-datetime');

module.exports = function(date){
    return new Promise((res, rej) => {
        let today = date || sd.format(new Date(), 'YYYY-MM-DD')
        exec(`git -C ${PROJECT_PATH} log --oneline --after="${today} 00:00" --before="${today} 23:59"`, {
            windowsHide: true
        }, (err, stdout, stderr) => {
            if(!err){
                let list = stdout.split('\n');
                list = list.reverse();
                list = list.filter(item => !!item);
                list = list.map((str, idx) => {
                    str = str.replace(/.*?\s/i, idx + 1 + '.')
                    return str
                });
                let ret = today + '提交:\n'+ list.join('\n');
                res(ret)
            }else{
                rej(err)
            }
        });
    })
}